#include <unistd.h>
#include <stdio.h>
#include <signal.h>

// http://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/
void handler(int signo) {
	if (signo == SIGUSR1 ) {
		printf("receive SIGUSR1\n");
		// ps -aux | grep ./a.out
		// kill -USR1 pid
	} else if (signo = SIGINT) { // ctrl + c
		printf("receive SIGINT\n");
	}
}

int main(void) {
	if (signal(SIGINT, handler) == SIG_ERR)
		printf("cannot catch SIGINT\n");

	if (signal(SIGKILL, handler) == SIG_ERR)
		printf("cannot catch SIGKILL\n");

	if (signal(SIGSTOP, handler) == SIG_ERR)
		printf("cannot catch SIGSTOP\n");

	if (signal(SIGUSR1, handler) == SIG_ERR)
		printf("\ncan't catch SIGUSR1\n");

	printf("my pid is %d\n", getpid());
	while (1) {
		sleep(10);
	}
	return 0;
}